<template>
    <div class="center">
        <el-card shadow="never" class="!border-none">
            <el-alert
                title="温馨提示： 1.审核用户的佣金提现申请；2.提现失败会退回全部金额"
                type="success"
                :closable="false"
                show-icon
            />
        </el-card>
        <el-card shadow="never" class="!border-none my-4">
            <div class="pb-[16px] pt-[16px]">
                <el-row :gutter="20">
                    <el-col :md="6" :span="12" class="flex mt-1">
                        <div class="flex">
                            <img style="width: 60px; height: 60px" src="../images/fivestart.png" />
                            <div class="flex-col items-center pt-[4px] ml-[10px]">
                                <div class="text-4xl font-medium">
                                    {{ statusData.total_earnings || '0.00' }}
                                </div>
                                <div class="text-tx-regular text-xs">佣金总金额</div>
                            </div>
                        </div>
                    </el-col>
                    <el-col :md="6" :span="12" class="flex mt-1">
                        <div class="flex">
                            <img style="width: 60px; height: 60px" src="../images/check.png" />
                            <div class="flex-col items-center pt-[4px] ml-[10px]">
                                <div class="text-4xl font-medium">
                                    {{ statusData.withdraw_success || '0.00' }}
                                </div>
                                <div class="text-tx-regular text-xs">已提现金额</div>
                            </div>
                        </div>
                    </el-col>
                    <el-col :md="6" :span="12" class="flex mt-1">
                        <div class="flex">
                            <img style="width: 60px; height: 60px" src="../images/charge.png" />
                            <div class="flex-col items-center pt-[4px] ml-[10px]">
                                <div class="text-4xl font-medium">
                                    {{ statusData.user_earnings || '0.00' }}
                                </div>
                                <div class="text-tx-regular text-xs">未提现金额</div>
                            </div>
                        </div>
                    </el-col>
                    <el-col :md="6" :span="12" class="flex mt-1">
                        <div class="flex">
                            <img style="width: 60px; height: 60px" src="../images/clock.png" />
                            <div class="flex-col items-center pt-[4px] ml-[10px]">
                                <div class="text-4xl font-medium">
                                    {{ statusData.withdraw_wait || '0.00' }}
                                </div>
                                <div class="text-tx-regular text-xs">待提现金额</div>
                            </div>
                        </div>
                    </el-col>
                </el-row>
            </div>
        </el-card>

        <el-card shadow="never" class="!border-none my-4">
            <el-form class="ls-form" :model="formData" inline>
                <el-form-item label="提现单号">
                    <el-input class="ls-input" v-model="formData.sn" placeholder="请输入" />
                </el-form-item>
                <el-form-item label="用户信息">
                    <el-input
                        class="ls-input"
                        v-model="formData.user_info"
                        placeholder="请输入用户信息"
                    />
                </el-form-item>
                <el-form-item label="提现方式">
                    <el-select v-model="formData.type" class="ls-input" placeholder="">
                        <el-option label="全部" value=""></el-option>
                        <el-option label="钱包余额" value="1"></el-option>
                        <el-option label="微信零钱" value="2"></el-option>
                        <el-option label="银行卡" value="3"></el-option>
                        <el-option label="微信收款码" value="4"></el-option>
                        <el-option label="支付宝收款码" value="5"></el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="提现时间">
                    <daterange-picker
                        style="width: 280px"
                        v-model:startTime="formData.start_time"
                        v-model:endTime="formData.end_time"
                    ></daterange-picker>
                </el-form-item>
                <el-form-item>
                    <div class="flex">
                        <el-button type="primary" @click="resetPage">查询</el-button>
                        <el-button @click="resetParams">重置</el-button>
                        <!-- <el-button @click="">导出</el-button> -->
                    </div>
                </el-form-item>
            </el-form>
        </el-card>

        <el-card class="mt-4 !border-none" shadow="never">
            <el-tabs class="-mt-2" v-model="formData.status" @tab-change="resetPage">
                <el-tab-pane :label="`全部(${statusData.all_count || 0})`" :name="0"> </el-tab-pane>
                <el-tab-pane :label="`待提现(${statusData.wait_count || 0})`" :name="1">
                </el-tab-pane>
                <el-tab-pane :label="`提现中(${statusData.ing_count || 0})`" :name="2">
                </el-tab-pane>
                <el-tab-pane :label="`提现成功(${statusData.success_count || 0})`" :name="3">
                </el-tab-pane>
                <el-tab-pane :label="`提现失败(${statusData.fail_count || 0})`" :name="4">
                </el-tab-pane>
            </el-tabs>
            <div class="mt-4">
                <el-table :data="pager.lists" size="large" v-loading="pager.loading">
                    <el-table-column label="提现单号" prop="sn" />
                    <el-table-column label="用户信息" prop="nickname"> </el-table-column>
                    <el-table-column label="提现金额" prop="money">
                        <template #default="{ row }">
                            <span>{{ `￥${row.money}` }}</span>
                        </template>
                    </el-table-column>

                    <el-table-column label="手续费">
                        <template #default="{ row }">
                            <span>{{ `￥${row.handling_fee}` }}</span>
                        </template>
                    </el-table-column>

                    <el-table-column label="到账金额">
                        <template #default="{ row }">
                            <span>{{ `￥${row.left_money}` }}</span>
                        </template>
                    </el-table-column>
                    <el-table-column label="提现方式" prop="type_desc"> </el-table-column>
                    <el-table-column label="提现状态" min-width="100">
                        <template #default="{ row }">
                            <el-tag type="success" v-if="row?.status == 1"> 待提现</el-tag>
                            <el-tag v-if="row?.status == 2" type="info"> 提现中</el-tag>
                            <el-tag v-if="row?.status == 3">提现成功</el-tag>
                            <el-tag type="danger" v-if="row?.status == 4">提现失败</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="用户备注" prop="apply_remark"> </el-table-column>
                    <el-table-column label="申请时间" prop="create_time">
                        <template #default="{ row }">
                            <span>
                                {{ row.create_time || '-' }}
                            </span>
                        </template>
                    </el-table-column>

                    <el-table-column label="操作" width="240" fixed="right">
                        <template #default="scope">
                            <div class="flex items-center">
                                <el-button
                                    type="primary"
                                    @click="handleresult(scope.row.id)"
                                    v-if="scope.row?.status == 2"
                                    >查询结果</el-button
                                >
                                <detail
                                    :id="scope.row?.id"
                                    :title="'详情'"
                                    @refresh="getLists"
                                ></detail>
                                <!-- 审核 -->
                                <div v-if="scope.row?.verify_btn == 1" class="flex items-center">
                                    <withdraw
                                        :id="scope.row?.id"
                                        :title="'审核'"
                                        @refresh="handletest"
                                    ></withdraw>
                                </div>
                                <!-- 转账 -->
                                <div v-if="scope.row?.transfer_btn == 1" class="flex items-center">
                                    <transfer
                                        :id="scope.row?.id"
                                        :title="'转账'"
                                        @refresh="handletest"
                                    ></transfer>
                                </div>
                            </div>
                        </template>
                    </el-table-column>
                </el-table>
            </div>

            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup>
import { withdrawList, serach } from '@/api/finance'
import Pagination from '@/components/pagination/index.vue'
import { usePaging } from '@/hooks/usePaging'
import detail from './components/detail.vue'
import withdraw from './components/withdraw.vue'
import transfer from './components/transfer.vue'

const formData = ref<any>({
    sn: '',
    user_info: '',
    type: '',
    start_time: '',
    end_time: '',
    status: 0
})
const statusData = ref<any>({})
const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: withdrawList,
    params: formData.value
})
const handletest = () => {
    getLists()
}
const getStatistice = async () => {
    const res = await withdrawList({})
    statusData.value = res.extend
}

// 重新退款
const handleRefund = (id: number) => {
    //   console.log(id);
    // await apiReRefund({ id: id });
}

onMounted(async () => {
    await getLists()
    await getStatistice()
})
const handleresult = async (id: number) => {
    await serach({ id })
    getLists()
}
</script>

<style lang="scss" scoped>
.ls-input {
    width: 280px;
}
.amount {
    font-family: 'PingFang HK';
    font-weight: 400;
    font-size: 32px;
    text-align: left;
    color: #333;
}
.text {
    font-family: 'PingFang HK';
    font-weight: 400;
    font-size: 14px;
    text-align: left;
    color: #666;
}
.el-tabs__nav-wrap::after {
    height: 1px !important;
}
.el-alert--success.is-light {
    background-color: #edefff;
    color: #4a5dff;
}
</style>
